<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="avicit.platform6.commons.utils.ViewUtil"%>
<%@page import="avicit.platform6.core.locale.PlatformLocalesJSTL"%>
<%@page import="java.util.Locale"%>
<%@page import="avicit.platform6.api.session.SessionHelper"%>
<%@page import="avicit.platform6.api.sysshirolog.impl.AfterLoginSessionProcess"%>
<%
    Object lang=session.getAttribute(AfterLoginSessionProcess.SESSION_CURRENT_LANGUAGE_CODE);
    String languageCode="zh_CN";
    if(lang!=null){
        languageCode=lang.toString();
    }
    Locale locale =SessionHelper.getLocaleByUser(request);
%>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>部门对应新增页</title>
    <base href="<%=ViewUtil.getRequestPath(request)%>">
    <jsp:include
            page="/avicit/platform6/component/common/EasyUIJsInclude.jsp"></jsp:include>
    <jsp:include page="/avicit/im/common/ImUIJSCSSInclude.jsp"></jsp:include>
    <link href="static/css/custom/lantop/css/custom.css" type="text/css"  rel="stylesheet">
    <script type="text/javascript" src="avicit/cbb/techclass/execlexp/ExcelExport.js"></script>
</head>
<script type="text/javascript"
        src="avicit/cbb/businessclass/fondsmanage/locale/language_<%=languageCode%>.js"></script>
<script type="text/javascript">
    var dialogId = '${dialogId}'; //打开页面传递的模块ID
    $(function(){
        freDataGridInit();
    });
    function freDataGridInit(){
        // 通过AJAX获取通用代码
        $.ajax({
            url : "platform/CompanyCorrespondenceController/getDept.json",
            type : 'post',
            dataType : 'json',
            data : {},
            async : false,
            success : function(data) {
                $('#columnsDataGrid').datagrid('loadData', data.rows.deptList);
                $('#colNamesDataGrid').datagrid('loadData', data.rows.oldDeptList);
            }
        });
    }

    function companyCorresAdd() {
        MaskUtil.mask();
        var row = $("#columnsDataGrid").datagrid('getChecked');
        var colNameRow = $("#colNamesDataGrid").datagrid('getChecked');
        var counterpartDeptNames = "";
        if (row.length == 1) {
            var id = row[0].ID;
            var deptName = row[0].DEPT_NAME;
            if (colNameRow.length >= 1) {
                for (var i = 0;i<colNameRow.length;i++){
                    counterpartDeptNames += colNameRow[i].GDDW +",";
                }
                $.ajax({
                    url: 'platform/CompanyCorrespondenceController/insertCompanyCorrespondence',
                    data: {
                        currentDeptId: id,
                        currentDeptName: deptName,
                        counterpartDeptNames : counterpartDeptNames
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function(result) {
                        MaskUtil.unmask();
                        if (result.flag == "0") {
                            $.messager.show({
                                title: '提示',//'提示',
                                msg: '操作成功!',//"操作成功!",
                                timeout: 2000,
                                showType: 'slide'
                            });
                            parent.freDataGrid();
                            closeWindow();
                        } else {
                            $.messager.show({
                                title: '提示',// '提示',
                                msg: '操作失败!',//"操作失败!",
                                timeout: 2000,
                                showType: 'slide'
                            });
                        }
                    }
                });
            }else{
                MaskUtil.unmask();
                $.messager.alert('提示', '请选择原有部门要对应的数据！', 'warning');
            }
        } else {
            MaskUtil.unmask();
            if (row != null && row.length < 1) {
                $.messager.alert('提示', '请选择现有部门要对应的数据！', 'warning');
            } else {
                $.messager.alert('提示', '请选择一条现有部门数据进行对应！', 'warning');
            }
        }
    }

    //返回
    function closeWindow() {
        if (parent != null && parent.$('#' + dialogId) != null) {
            parent.$('#' + dialogId).dialog('close'); //关闭当前窗口
        }
    }
    function getNewDeptResultByInput() {
        // 通过AJAX获取通用代码
        $.ajax({
            url : "platform/CompanyCorrespondenceController/getDept.json",
            type : 'post',
            dataType : 'json',
            data : {inputWord:$('#newDeptQuery').val()},
            async : false,
            success : function(data) {
                $('#columnsDataGrid').datagrid('loadData', data.rows.deptList);
            }
        });
    }
    function getOldDeptResultByInput() {
        // 通过AJAX获取通用代码
        var row = $("#columnsDataGrid").datagrid('getChecked');
        $.ajax({
            url : "platform/CompanyCorrespondenceController/getOldDept.json",
            type : 'post',
            dataType : 'json',
            data : {inputWord:$('#oldDeptQuery').val(),newDeptName:""},
            async : false,
            success : function(data) {
                $('#colNamesDataGrid').datagrid('loadData', data.rows.oldDeptList);
            }
        });
    }
    function keyDownQuery(type) {
        if (event.keyCode == 13) {
            if("1"==type){
                getNewDeptResultByInput();
            } else if ("2"==type){
                getOldData();
            }
        }
    }
    function getOldData() {
        MaskUtil.mask();
        var rows = $("#columnsDataGrid").datagrid('getChecked');
        var newDeptName;
        if(rows.length>0){
            newDeptName = rows[0].DEPT_NAME;
        }
        // 通过AJAX获取通用代码
        $.ajax({
            url : "platform/CompanyCorrespondenceController/getOldDept.json",
            type : 'post',
            dataType : 'json',
            data : {inputWord:$('#oldDeptQuery').val(),newDeptName:newDeptName},
            async : false,
            success : function(data) {
                $('#colNamesDataGrid').datagrid('loadData', data.rows.oldDeptList);
            }
        });
        MaskUtil.unmask();
    }
</script>
<style>
    .datagrid-body td{
        background:none !important;
    }
    #table_con .datagrid-body  table{
        width:100% !important;
    }
    #west .datagrid-header-check{
        visibility: hidden;
    }
</style>
<body class="easyui-layout">
<!-- 现有部门 -->
<div id="west" data-options="region:'west',split:false,border:true" style="width:350px;border:1px solid #dedede;">
    <div id = "newDept"
         style="background: white; width: 346px; height: 25px; margin-right: 10px; border-radius: 3px; border: 1px solid #ccc; float: left;" class="datagrid-toolbar">
        <input placeholder="快速检索" type="text" id="newDeptQuery"
               onblur="getNewDeptResultByInput()" onkeydown="keyDownQuery('1');"
               style="float: left; box-sizing: border-box; padding-left: 5px; width: 93%; height: 25px; outline: none; border: none;"/>
        <img src="avicit/im/lantop/common/search/image/icon_tool14.png" onclick="getNewDeptResultByInput()"
             style="float: right; margin-top: 2px; margin-right: 2px;cursor: pointer;">
    </div>
    <table id="columnsDataGrid" class="easyui-datagrid"
           data-options="
				fit:true,
				animate: true,
				collapsible: false,
				fitColumns: true,
				autoRowHeight: false,
				singleSelect: true,
				striped:true,
				scrollbarSize:0,
				method: 'post',
				onDblClickRow: oneAdd,
				rowStyler: rowColor,
				remoteSort : true,
				onCheck: getOldData,
				toolbar: '#newDept'
			">

        <thead>
        <tr>
            <sec:accesscontrollist  hasPermission="3" domainObject ="LantopCompanyCorrespondence_datagrid_id">
                <th data-options="field:'ID', halign:'center',checkbox:true"
                    title="全选" width="20">全选</th>
            </sec:accesscontrollist>
            <sec:accesscontrollist  hasPermission="3" domainObject ="LantopCompanyCorrespondence_datagrid_deptName">
                <%-- 全宗 --%>
                <th data-options="field:'DEPT_NAME', halign:'center', align:'center', sortable:false, width: 200"
                    title="现有部门">现有部门</th>
            </sec:accesscontrollist>
        </tr>
        </thead>
    </table>
</div>
<!-- 对应部门 -->
<div data-options="region:'east',iconCls:'icon-reload',split:false,border:true" style="width:350px;border:1px solid #dedede;"  id="table_con">
    <div id = "oldDept" class="datagrid-toolbar"
         style="background: white; width: 346px; height: 25px; margin-right: 10px; border-radius: 3px; border: 1px solid #ccc; float: left;">
        <input placeholder="快速检索" type="text" id="oldDeptQuery"
               onblur="getOldData()" onkeydown="keyDownQuery('2');"
               style="float: left; box-sizing: border-box; padding-left: 5px; width: 93%; height: 25px; outline: none; border: none;"/>
        <img src="avicit/im/lantop/common/search/image/icon_tool14.png" onclick="getOldData()"
             style="float: right; margin-top: 2px; margin-right: 2px;cursor: pointer;">
    </div>
    <table id="colNamesDataGrid" class="easyui-datagrid"
           data-options="
				fit:true,
				animate: true,
				collapsible: false,
				fitColumns: true,
				autoRowHeight: false,
				singleSelect: false,
				striped:true,
				scrollbarSize:0,
				method: 'post',
				rowStyler: rowColor,
				remoteSort : false,
				toolbar: '#oldDept'
			">
        <thead>
        <tr>
            <sec:accesscontrollist  hasPermission="3" domainObject ="LantopCompanyCorrespondence_datagrid_id">
                <th data-options="field:'GDDWID', halign:'center',checkbox:true"
                    title="全选" width="20">全选</th>
            </sec:accesscontrollist>
            <sec:accesscontrollist  hasPermission="3" domainObject ="LantopCompanyCorrespondence_datagrid_orgName">
                <%-- 旧部门 --%>
                <th data-options="field:'GDDW', halign:'center', align:'center', sortable:false, width: 200"
                    title="旧部门">原有部门</th>
            </sec:accesscontrollist>
        </tr>
        </thead>
    </table>
</div>
<!-- button事件 -->
<div data-options="region:'south',split:false,border:true,align:'center'" style="overflow-y: hidden;height:50px;">
    <div id="toolbar"  style="margin: 10px">
        <table align="center">
            <tr>
                <td width="80px">
                    <sec:accesscontrollist  hasPermission="3" domainObject="excel_export_button_add" >
                    <a class="easyui-linkbutton  selbtn"  onclick="companyCorresAdd();" href="javascript: void(0);">
                        <img  src="avicit/im/lantop/common/search/image/icon_tool34_blue.png">
                        <span class="selbtc">对应</span>
                    </a>
                    </sec:accesscontrollist>
                </td>
                <td>
                    <sec:accesscontrollist  hasPermission="3" domainObject="excel_export_button_cancle" >
                        <a class="easyui-linkbutton  selbtn"  onclick="closeWindow();" href="javascript: void(0);">
                            <img  src="avicit/im/lantop/common/search/image/icon_tool42_blue.png">
                            <span class="selbtc">返回</span>
                        </a>
                    </sec:accesscontrollist>
                </td>
            </tr>
        </table>
    </div>
</div>
</body>
<!-- 滚动条样式设置  yangzengzhi 2019-06-25-->
<script type="text/javascript" src="static/js/platform/index/js/divscroll.js" ></script>
<script>
    $(function(){
        $(".datagrid-body").perfectScrollbar();
    });
</script>
<!-- end-->
</html>